package zheezes.util;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

/**
 * @author chen han
 *
 * this is help to create resoure's Java source codes
 */
public class ResourceUtil {
	public final static void work(InputStreamReader reader,	OutputStreamWriter writer) {
		String aline = null;
		String line = null;
		String var = null;
		int idx = -1;
		BufferedReader in = new BufferedReader(reader);
		BufferedWriter out = new BufferedWriter(writer);
		try {
			while ((aline = in.readLine()) != null) {
				if (aline.startsWith("#")) {
					line = "//" + aline.substring(1);
				} else if ((idx = aline.indexOf('=')) >= 0) {
					line = aline.substring(0, idx);
					var = line.toUpperCase().replace('.', '_');
					line = "public static final String " + var + " = " + "\"" + line + "\";";
				} else {
					line = aline;
				}
				out.write(line);
				out.newLine();
			}
			out.close();
			in.close();
		} catch (IOException e) {
		}
	}

	public static void main(String[] args) throws Exception {
		InputStreamReader reader = new InputStreamReader(new FileInputStream(ClassLoader.getSystemResource("resource_zh_CN.properties").getFile()));
		OutputStreamWriter writer = new OutputStreamWriter(System.out);
		work(reader, writer);
	}
}
